﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;

namespace PyroGen
{
    public static class SettingsLoader
    {
        public static Dictionary<string, Tuple<CodeType, Terminator>> LoadDefaultTags()
        {
            var positionDescription = new Dictionary<string, Tuple<CodeType, Terminator>>();
            var configDescription = new Dictionary<string, Tuple<CodeType, Terminator>>
                                        {
                                            {
                                                "startExpression",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.Expression,
                                                 Terminator.Start)
                                            },
                                            {
                                                "stopExpression",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.Expression,
                                                 Terminator.End)
                                            },
                                            {
                                                "startSourceCode",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.Code,
                                                 Terminator.Start)
                                            },
                                            {
                                                "stopSourceCode",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.Code,
                                                 Terminator.End)
                                            },
                                            {
                                                "startConfigExpression",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.ConfigCode,
                                                 Terminator.Start)
                                            },
                                            {
                                                "stopConfigExpression",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.ConfigCode,
                                                 Terminator.End)
                                            },
                                            {
                                                "startScript",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.ScriptCode,
                                                 Terminator.Start)
                                            },
                                            {
                                                "stopScript",
                                                new Tuple<CodeType, Terminator>
                                                (CodeType.ScriptCode,
                                                 Terminator.End)
                                            }
                                        };

            foreach (string s in configDescription.Keys)
            {
                positionDescription[ConfigurationManager.AppSettings[s]] = configDescription[s];
            }

            return positionDescription;
        }

        public static string GetDefaultFile()
        {
            try
            {
                string name = ConfigurationManager.AppSettings["defaultSourceFileLocation"];
                Debug.Assert(!string.IsNullOrEmpty(name));
                Debug.WriteLine("getDefaultFile: proto name - " + name);
                var fs = new FileStream(name, FileMode.Open, FileAccess.ReadWrite);
                fs.Close();
                return name;
            }
            catch (IOException ex)
            {
                Debug.Write(ex);
                return null;
            }
        }


        public static string GetNamespaceKeyword()
        {
            return ConfigurationManager.AppSettings["namespaceKeyword"];
        }

        public static string GetAssemblyKeyword()
        {
            return ConfigurationManager.AppSettings["assemblyKeyword"];
        }

        public static string GetIncludeKeyword()
        {
            return ConfigurationManager.AppSettings["includeKeyword"];
        }

        public static string GetExecuteKeyword()
        {
            return ConfigurationManager.AppSettings["executeKeyword"];
        }

        public static string GetBeautifyKeyword()
        {
            return ConfigurationManager.AppSettings["beautifyKeyword"];
        }

        public static string GetLanguageKeyword()
        {
            return ConfigurationManager.AppSettings["languageKeyword"];
        }

        public static string GetPropertyKeyword()
        {
            return ConfigurationManager.AppSettings["propertyKeyword"];
        }

        public static string GetPropertyTypeKeyword()
        {
            return ConfigurationManager.AppSettings["propertyTypeKeyword"];
        }

        public static string GetPropertyValueKeyword()
        {
            return ConfigurationManager.AppSettings["propertyTalueKeyword"];
        }
    }
}